import { createRouter, createWebHashHistory} from 'vue-router'
import routes from './routes'
import {Toast} from "vant";

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) =>{
  if(to.meta.isAuth){
    // 登录后在storage存储用户信息
    if(localStorage.isLogin === 'login'){
      next()
    }else{
      next('/login')
      Toast('请先登录')
    }
  }else{
    next()
  }
})

export default router